﻿using Commons.Models.Functions;
using Commons.Models.Stats;
using System;

namespace Commons.Models.TradeValues
{
	[Serializable]
	public class UserStatTradeValue : TradeValue, IMergeableTradeValue
	{
		public IStatUnit Unit { get; protected set; }
		public int Delta { get; protected set; }
		public IFunction<double, double> Function { get; set; }

		public UserStatTradeValue(IStatUnit unit, int delta)
			: base("userStat")
		{
			this.Unit = unit;
			this.Delta = delta;
		}

		public ITradeValue  Merge (ITradeValue other)
		{
			UserStatTradeValue otherTv = (UserStatTradeValue) other;
			if(otherTv.Unit != Unit)
			{
				throw new ArgumentException("UserStatTradeValue unit mismatch: "+otherTv.Unit+"!="+Unit,"other");
			}
			return new UserStatTradeValue(Unit, Delta + otherTv.Delta);
		}
		
		public string GetKey ()
		{
			return string.Format("{0}_{1}", Type, Unit);
		}
	}
}
